package com.logic.UsersLocation;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.beans.LocationBean;
import com.factory.db.DBFactory;

public class GetUsersLocation {

	public List<LocationBean> getLocationList( String userid ){

		Connection conn = null;

		PreparedStatement pst = null;

		ResultSet rs = null;

		conn = DBFactory.getDBConnectionInstance( DBFactory.TYPE_MYSQL ).getDBConnection();

		List<LocationBean> list = new ArrayList<LocationBean>();

		String sql = "select location,type,id,add_time from db.jiankong_data_info_table  where controlled_id= ? and location != '' ORDER BY id DESC limit 0,200";


		try {
			pst = conn.prepareStatement( sql );
			pst.setString( 1, userid );

			rs = pst.executeQuery();

			while (rs.next()) {

				LocationBean bean = new LocationBean();

				bean.setLocation( rs.getString("location") );
				bean.setType( rs.getString("type") );
				bean.setAdd_time( rs.getString("add_time") );
				bean.setId( rs.getInt("id"));

				list.add( bean );

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{




			if( rs != null ){

				try {
					rs.close();

					rs = null;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			if( pst != null ){

				try {
					pst.close();

					pst = null;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}


		}
		
		return list;

	}
}
